package com.johnlee.eureka_server.sentinel_springcloud;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    // 定义限流资源和限流降级回调函数
    @SentinelResource(value = "Sentinel_SpringCloud", blockHandler = "exceptionHandler")
    @GetMapping("helloSpringCloudAnn")
    public String helloSpringCloudAnn() {
        return "Hello Sentinel Spring Cloud Annotation";
    }

    // blockHandler 函数，原方法调用被限流/降级/系统保护的时候调用
    public String exceptionHandler(BlockException ex) {
        ex.printStackTrace();
        return "busy";
    }
}
